public class Test_8_22 {

    //剑指Offer：JZ3 数组中重复的数字
    public int duplicate (int[] numbers) {
        int ret = -1;
        int[] count = new int[numbers.length];
        for(int i = 0; i < numbers.length; i++) {
            count[numbers[i]]++;
            if(count[numbers[i]] >1) {
                ret = numbers[i];
                break;
            }
        }
        return ret;
    }

    //JZ4 二维数组中的查找
    public boolean Find (int target, int[][] array) {
        int col = array[0].length;
        int i = array.length - 1;
        int j = 0;
        while(i >= 0 && j < col) {
            if(target == array[i][j]) {
                return true;
            }else if(target > array[i][j]) {
                j++;
            }else {
                i--;
            }
        }
        return false;
    }

    //JZ5 替换空格
    public String replaceSpace (String s) {
        StringBuilder ret = new StringBuilder();
        for(int i = 0; i < s.length(); i++) {
            if(s.charAt(i) == ' ') {
                ret.append("%20");
            }else {
                ret.append(s.charAt(i));
            }
        }
        return ret.toString();
    }


    //Java语法基础：JAVA49 判断素数个数
    public static void method(int start, int end) {
        int count=0;
        int max = start>end?start:end;
        int min = max ^ start ^ end;
        start = min;
        end = max;
        for(int i = start; i <= end; i++) {
            int j = 2;
            for(; j <= Math.sqrt((double)i); j++) {
                if(i % j == 0) {
                    break;
                }
            }
            if(i % j != 0) {
                count++;
            }
        }

        System.out.println(start+"到"+end+"之间有"+count+"个大于2的素数");
    }
}
